package com.dyz.leetcode;

import java.util.ArrayList;
import java.util.List;

public class LetterCombinations17 {
    //定义对应数字的字符
    static String[] a = new String[]{"","","abc","def", "ghi","jkl","mno","pqrs","tuv","wxyz"};
    static StringBuilder sb = new StringBuilder();
    public List<String> letterCombinations(String digits) {
        List<String> answer = new ArrayList<>();
        if(digits==null|| digits.length()==0){return answer;}
        //开始回溯
        zuhe(digits, 0, answer);

        return answer;
    }

    private void zuhe(String digits, int n, List<String> answer) {
        if(n== digits.length()){
            answer.add(sb.toString());
            return;
        }
        for (int i=0; i<a[digits.charAt(n)-'0'].length(); i++){
            sb.append(a[digits.charAt(n)-'0'].charAt(i));
            zuhe(digits, n+1, answer);
            sb.deleteCharAt(sb.length()-1);
        }
    }
    //测试
    public static void main(String[] args) {
        List<String> x = new LetterCombinations17().letterCombinations("23");
        System.out.println(x.toString());
    }


}
